﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading;
using System.IO;
using System.Windows.Media.Imaging;

namespace S7
{
    public class Info
    {
        public static IPAddress currentIP = GetLocalIP();
        public static int currentPort = Properties.Settings.Default.Port;

        public static TcpServer server;

        public static Queue<M7.NCustomer> MalesQueue;
        public static Queue<M7.NCustomer> FemalesQueue;
        public static Dictionary<Genre, int> MusicVotes;
        public static Dictionary<TV, int> TVVotes;
        public static Dictionary<AC, int> ACVotes;

        public static M7.NSong CurrentSong = new M7.NSong("Unkown", "Unkown", "Unknown", "No Lyrics available", "Unkown");
        public static string News = Properties.Settings.Default.News;

        public static List<M7.NSong> PlayingList;
        public static Thread thrCalculateVotes;
        public static Random rand = new Random();

        public static Window1 window;
        public static S7.Windows.Chat.ShowChat showChatWindow;
        public static S7.Windows.Chat.EnterChat enterChatWindow;

        public static string Capitalize(string Text)
        {
            if (Text.Equals(String.Empty))
            {
                return "";
            }
            else
            {
                char[] chars = Text.ToLowerInvariant().ToCharArray();
                chars[0] = chars[0].ToString().ToUpperInvariant().ToCharArray()[0];
                StringBuilder sb = new StringBuilder();
                foreach (var c in chars)
                {
                    sb.Append(c);
                }
                return sb.ToString();
            }
        }

        public static List<string> ToStringsList(string text)
        {
            List<string> lstStrings = new List<string>();
            var qu = from c in text
                     select c;
            StringBuilder sb = new StringBuilder();
            foreach (var chars in qu)
            {
                if (chars == ' '|| chars == ',' || chars == '.' || chars == '*' || chars == ';' || chars == '(' || chars == ')' || chars == '-' || chars == '$' || chars == '%' || chars == '@')
                {
                    lstStrings.Add(sb.ToString());
                    sb.Remove(0, sb.Length);
                }
                else
                {
                    sb.Append(chars);
                }
            }

            if (sb.ToString() != "")
            {
                lstStrings.Add(sb.ToString()); 
            }
            return lstStrings;
        }

        public static IPAddress GetLocalIP()
        {
            string pcname = Dns.GetHostName();
            IPAddress[] ips = Dns.GetHostAddresses(pcname);
            var IPs = from ip in ips
                      where ip.ToString().StartsWith("192")
                      select ip;
            if (IPs.ToList().Count.Equals(0))
            {
                return IPAddress.Parse("127.0.0.1");
            }
            else
            {
                return IPs.ToList()[0];
            }
        }
    }
}
